#include <stdio.h>

struct Book
{
    char title[31];
    float price;
};

int main()
{
    int n;
    scanf("%d", &n);
    getchar();
    struct Book books[100];

    // 读取书籍信息
    for (int i = 1; i <= n; i++)
    {
        int len = 0;
        char c = getchar();
        while(c != '\n')
        {
            books[i].title[len++] = c;
            c = getchar();
        }
        books[i].title[len] = '\0';
        scanf("%f", &books[i].price);     // 读取价格
        getchar();
    }

    // 初始化最大最小值的索引
    int maxIndex = 1, minIndex = 1;

    // 如果n > 1，才执行比较
    for (int i = 1; i <= n; i++)
    {
        if (books[i].price > books[maxIndex].price)
        {
            maxIndex = i;
        }
        if (books[i].price < books[minIndex].price)
        {
            minIndex = i;
        }
    }

    // 输出最高和最低价格的书籍
        printf("%.2f, %s\n", books[maxIndex].price, books[maxIndex].title);

        printf("%.2f, %s\n", books[minIndex].price, books[minIndex].title);

    return 0;
}
